
import { getBanks,fileDelete,fileGet,contracLaunch,contractDownload,contracRevoke,contracUrge } from '@/api/user'
import { parseTime } from '@/utils/index'
import { Message,MessageBox,Loading } from 'element-ui'
import tablePro from '../table/table_ss'

export class JueceCommon {
    constructor(context){
        this.context = context;

        this.MessageBox = MessageBox
    }

    tableHead_EI(data) { //企业信息录入
        const tableHeadData = [];
        for (let i in data) {
            let obj = {};
            switch (i) {
            case 'entName':
                obj.prop = i;
                obj.label = '企业名称'
                //
                obj.minWidth = '45';
                obj.tableOrder = 13
                break
            case 'entUniId':
                obj.prop = i;
                obj.label = '企业信用代码'
                obj.tableOrder = 14
                break 
            case 'no':
                obj.prop = i;
                obj.label = '批次号'
                obj.tableOrder =  this.context.$route.path === '/inputSearch' ? 12 : 15
                obj.isLink = true; 
                break         
            case 'isReg':
                obj.prop = i;
                obj.label = '是否注册'
                obj.tableOrder = 15
                break         
            case 'regTime_view':
                obj.prop = i;
                obj.label = '注册时间'
                obj.tableOrder = 16
                break
            case 'createTime_view':
                obj.prop = i;
                obj.label = '录入时间'
                obj.tableOrder = 17
                break
            // case 'bankName':
            //     obj.prop = i;
            //     obj.label = '银行'
            //     obj.tableOrder = 17
            //     obj.minWidth = '22'
            //     break
            // case 'region':
            //     obj.prop = i;
            //     obj.label = '区县'
            //     obj.tableOrder = 17
            //     obj.minWidth = '16'
            //     break
            // case 'singerPhone':
            //     obj.prop = i;
            //     obj.label = '签署人联系方式'
            //     obj.tableOrder = 18
            //     obj.minWidth = '28'
            //     break  
            // case 'statusDetail':
            //     obj.prop = i;
            //     obj.label = '合同状态'
            //     obj.tableOrder = 18
            //     obj.minWidth = '20'
            //     break
            // case 'type':
            //     obj.prop = i;
            //     obj.label = '业务类型'
            //     obj.tableOrder = 18
            //     obj.minWidth = '30'
            //   break 
            // case 'fileUploadTime':
            //     obj.prop = 'fileUploadTime_view';
            //     obj.label = '创建时间'
            //     obj.tableOrder = 19
            //     obj.minWidth = '30'
            //   break    
            default:
                continue;
                break;
            }
            tableHeadData.push(obj);
        }

        // tableHeadData.push({  
        //     prop:'operate',
        //     label:'操作',
        //     tableOrder : 50,
        //     minWidth:'100',
        //     operation:this.context.$route.path === '/contractList'  ? [
        //         {name: '下载合同', colorType:'info',width:"80px", clickFun:this.download},
        //         {name: '发起签署', width:"80px",colorType:'success', clickFun: this.launch},
        //         {name: '签署链接', width:"80px", clickFun: this.context.checkGetSignUrl},
        //         {name: '催签',colorType:'primary', clickFun: this.urge},
        //         {name: '撤销',colorType:'warning', clickFun: this.revoke},
        //         {name: '删除', colorType:'danger', clickFun: this.context.deleteRow},
        //     ] : [
        //         {name: '下载合同', colorType:'info',width:"80px", clickFun:this.download},
        //         {name: '发起签署', width:"80px",colorType:'success', clickFun: this.launch},
        //         {name: '签署链接', width:"80px", clickFun: this.context.checkGetSignUrl},
        //         {name: '催签',colorType:'primary', clickFun: this.urge},
        //         {name: '撤销',colorType:'warning', clickFun: this.revoke},
        //     ]
        // });
        // tableHeadData.push({
        //     prop:'operate',
        //     label:'操作',
        //     tableOrder : 57,
        //     minWidth:'50',
        //     operation:[
        //         {name: '签署链接', colorType:'primary',width:'64px', clickFun: this.checkOperation}
        //     ]
        // });
        tableHeadData.sort((a, b) => a.tableOrder - b.tableOrder);
        return Object.freeze(tableHeadData)
    }

    tableHead_ES(data) { //企业数据查询
        const tableHeadData = [];
        for (let i in data) {
            let obj = {};
            switch (i) {
                case 'entUniId':
                    obj.prop = i;
                    obj.label = '统一社会信用代码'
                    obj.tableOrder = 13
                    //obj.minWidth = '70'
                    obj.width = '180'
                    obj.fixed = true
                    break 
                case 'entName':
                    obj.prop = i;
                    obj.label = '企业名称(录入)'
                    obj.tableOrder = 14
                    obj.fixed = true
                    obj.width = '250'
                    break
                case 'regName':
                    obj.prop = i;
                    obj.label = '企业名称'
                    obj.tableOrder = 15
                    obj.fixed = true
                    obj.width = '250'
                    break    
                case 'isReg':
                    obj.prop = i;
                    obj.label = '是否注册'
                    obj.tableOrder = 16
                    obj.width = '70'
                    obj.fixed = true
                    break         
                case 'regTime':
                    obj.prop = 'regTime_view';
                    obj.label =  '平台注册时间'
                    obj.tableOrder = 16
                    obj.minWidth = '120'
                    break         
                case 'gszcTime':
                    obj.prop = 'gszcTime_view';
                    obj.label =  '工商注册时间'
                    obj.tableOrder = 16
                    obj.minWidth = '120'
                    break         
                case 'gszc6Month':
                    obj.prop = i;
                    obj.label = '注册大于6个月'
                    obj.tableOrder = 16
                    obj.minWidth = '70'
                    break         
                case 'sb6FromTo':
                    obj.prop = i;
                    obj.label = '社保6个月区间'
                    obj.tableOrder = 17
                    obj.minWidth = '130'
                    break
                case 'sb6Times':
                    obj.prop = i;
                    obj.label = '6个月社保次数'
                    obj.tableOrder = 18
                    obj.minWidth = '130'
                    break
                case 'sb12FromTo':
                    obj.prop = i;
                    obj.label = '社保12个月区间'
                    obj.tableOrder = 19
                    obj.minWidth = '130'
                    break
                case 'sb12Times':
                    obj.prop = i;
                    obj.label = '12个月社保次数'
                    obj.tableOrder = 20
                    obj.minWidth = '130'
                    break    
                case 'tax6FromTo':
                    obj.prop = i;
                    obj.label = '纳税前六个月区间'
                    obj.tableOrder = 21
                    obj.minWidth = '130'
                    break 
                case 'tax6Times':
                    obj.prop = i;
                    obj.label = '6个月纳税次数'
                    obj.tableOrder = 22
                    obj.minWidth = '130'
                    break          
                case 'xzgxf':
                    obj.label = '是否限高'
                    obj.tableOrder = 32
                    obj.minWidth = '45'
                    obj.isCustomize = true
                    obj.customize = tablePro
                    obj.prop2 = i;
                    break
                case 'bzx':
                    obj.label = '是否被执行'
                    obj.tableOrder = 33
                    obj.minWidth = '60'
                    obj.isCustomize = true
                    obj.customize = tablePro
                    obj.prop2 = i;
                    break
                case 'laxx':
                    obj.label = '是否立案'
                    obj.tableOrder = 34
                    obj.minWidth = '45'               
                    obj.isCustomize = true
                    obj.customize = tablePro
                    obj.prop2 = i;
                    break  
                case 'ktgg':
                    obj.label = '是否开庭'
                    obj.tableOrder = 35
                    obj.minWidth = '45'
                    obj.isCustomize = true
                    obj.customize = tablePro
                    obj.prop2 = i;
                    break
                case 'nsxy':
                    obj.prop = i;
                    obj.label = '纳税等级'
                    obj.tableOrder = 36
                    obj.minWidth = '50'
                  break 
                //  case 'nsxyB':
                //     obj.prop = i;
                //     obj.label = '是否B以上'
                //     obj.tableOrder = 37
                //     obj.minWidth = '50'
                //   break   
                case 'isOK':
                    obj.prop = i;
                    obj.label = '综合查询结果'
                    obj.tableOrder = 37
                    obj.minWidth = '70'
                  break   
                case 'createTime':
                    obj.prop = 'createTime_view';
                    obj.label = '查询时间'
                    obj.tableOrder = 47
                    obj.minWidth = '120'
                  break   
                case 'dataTime':
                    obj.prop = 'dataTime_view';
                    obj.label = '返回数据时间'
                    obj.tableOrder = 48
                    obj.minWidth = '120'
                  break  
                default:
                    continue;
                    break;
            }
            tableHeadData.push(obj);
        }
        if(this.context.$route.path === '/historySearch'){
            const NoObj = {
                prop : 'no',
                label : '批次号',
                tableOrder: '12',
                minWidth : '120'
            }
            tableHeadData.push(NoObj);
        }
        
        // tableHeadData.push({  
        //     prop:'operate',
        //     label:'操作',
        //     tableOrder : 50,
        //     minWidth:'100',
        //     operation:this.context.$route.path === '/contractList'  ? [
        //         {name: '下载合同', colorType:'info',width:"80px", clickFun:this.download},
        //         {name: '发起签署', width:"80px",colorType:'success', clickFun: this.launch},
        //         {name: '签署链接', width:"80px", clickFun: this.context.checkGetSignUrl},
        //         {name: '催签',colorType:'primary', clickFun: this.urge},
        //         {name: '撤销',colorType:'warning', clickFun: this.revoke},
        //         {name: '删除', colorType:'danger', clickFun: this.context.deleteRow},
        //     ] : [
        //         {name: '下载合同', colorType:'info',width:"80px", clickFun:this.download},
        //         {name: '发起签署', width:"80px",colorType:'success', clickFun: this.launch},
        //         {name: '签署链接', width:"80px", clickFun: this.context.checkGetSignUrl},
        //         {name: '催签',colorType:'primary', clickFun: this.urge},
        //         {name: '撤销',colorType:'warning', clickFun: this.revoke},
        //     ]
        // });
        // tableHeadData.push({
        //     prop:'operate',
        //     label:'操作',
        //     tableOrder : 57,
        //     minWidth:'50',
        //     operation:[
        //         {name: '签署链接', colorType:'primary',width:'64px', clickFun: this.checkOperation}
        //     ]
        // });
        tableHeadData.sort((a, b) => a.tableOrder - b.tableOrder);
        return Object.freeze(tableHeadData)
    }

    tableHead_Ss(data) { //查询统计
        const tableHeadData = [];
        for (let i in data) {
            let obj = {};
            switch (i) {
                case 'createTime':
                    obj.prop = i;
                    obj.label = '日期'
                    obj.tableOrder = 10
                    obj.width = '150'
                    break 
                case 'no':
                    obj.prop = i;
                    obj.label = '批次号'
                    obj.tableOrder = 20
                    obj.width = '120'
                    break
                case 'entNum':
                    obj.prop = i;
                    obj.label = '企业数量'
                    obj.tableOrder = 30
                    break           
                case 'gszcNum':
                    obj.prop = i;
                    obj.label = '工商注册条数'
                    obj.tableOrder = 41
                    break    
                case 'nsxyNum':
                    obj.prop = i;
                    obj.label = '纳税等级条数'
                    obj.tableOrder = 42
                    break  
                case 'sbNum':
                    obj.prop = i;
                    obj.label = '社保条数'
                    obj.tableOrder = 43
                    break    
                case 'xzgxfNum':
                    obj.prop = i;
                    obj.label = '限制高消费条数'
                    obj.tableOrder = 44
                    break   
                case 'laxxNum':
                    obj.prop = i;
                    obj.label = '立案信息条数'
                    obj.tableOrder = 45
                    break   
                case 'ktggNum':
                    obj.prop = i;
                    obj.label = '开庭条数'
                    obj.tableOrder = 45
                    break      
                case 'bzxNum':
                    obj.prop = i;
                    obj.label = '被执行条数'
                    obj.tableOrder = 47
                    break                    
                case 'userName':
                    obj.prop = i;
                    obj.label =  '用户名称'
                    obj.tableOrder = 50
                    break         
                case 'orgName':
                    obj.prop = i;
                    obj.label =  '对应机构名称'
                    obj.tableOrder = 60
                    obj.minWidth = '150'
                    break         
                
                default:
                    continue;
                    break;
            }
            tableHeadData.push(obj);
        }

       
        tableHeadData.sort((a, b) => a.tableOrder - b.tableOrder);
        return Object.freeze(tableHeadData)
    }

    tableHead_bzx(data) { //被执行
        const tableHeadData = [];
        for (let i in data) {
            let obj = {};
            switch (i) {
                case 'name':
                    obj.prop = i;
                    obj.label = '企业名称'
                    obj.tableOrder = 10
                    obj.minWidth = '250'
                    break 
                case 'amount':
                    obj.prop = i;
                    obj.label = '执行标的'
                    obj.tableOrder = 20
                    
                    break
                case 'caseNo':
                    obj.prop = i;
                    obj.label = '案号'
                    obj.tableOrder = 30
                    obj.minWidth = '250'
                    break    
                case 'number':
                    obj.prop = i;
                    obj.label = '企业证照号'
                    obj.tableOrder = 40
                    obj.minWidth = '150'
                    break         
                case 'type':
                    obj.prop = i;
                    obj.label =  '被执行人类型'
                    obj.tableOrder = 50
                    break         
                case 'court':
                    obj.prop = i;
                    obj.label =  '执行法院'
                    obj.tableOrder = 60
                    obj.minWidth = '250'
                    break         
                case 'caseDate':
                    obj.prop = i;
                    obj.label =  '立案时间'
                    obj.tableOrder = 70
                    obj.minWidth = '120'
                    break         
                case 'status':
                    obj.prop = i;
                    obj.label =  '执行状态'
                    obj.tableOrder = 80
                    break         
                
                default:
                    continue;
                    break;
            }
            tableHeadData.push(obj);
        }

       
        tableHeadData.sort((a, b) => a.tableOrder - b.tableOrder);
        return Object.freeze(tableHeadData)
    }

    tableHead_ktgg(data) { //开庭
        const tableHeadData = [];
        for (let i in data) {
            let obj = {};
            switch (i) {
                case 'content':
                    obj.prop = i;
                    obj.label = '开庭内容'
                    obj.tableOrder = 10
                    obj.minWidth = '300'
                    break 
                case 'pureRole':
                    obj.prop = i;
                    obj.label = '当事人身份'
                    obj.tableOrder = 20
                    break
                case 'caseNo':
                    obj.prop = i;
                    obj.label = '案号'
                    obj.tableOrder = 30
                    obj.minWidth = '100'
                    break    
                case 'court':
                    obj.prop = i;
                    obj.label = '开庭法院'
                    obj.tableOrder = 40
                    obj.minWidth = '150'
                    break         
                case 'caseCause':
                    obj.prop = i;
                    obj.label =  '规则后案由'
                    obj.tableOrder = 50
                    obj.minWidth = '150'
                    break         
                case 'hearingDate':
                    obj.prop = i;
                    obj.label =  '开庭日期'
                    obj.tableOrder = 60
                    obj.minWidth = '130'
                    break         
                case 'judgeType':
                    obj.prop = i;
                    obj.label =  '案件类型'
                    obj.tableOrder = 70
                    break         
                case 'department':
                    obj.prop = i;
                    obj.label =  '承办部门'
                    obj.tableOrder = 80
                    break         
                case 'tribunal':
                    obj.prop = i;
                    obj.label =  '法庭'
                    obj.tableOrder = 90
                    obj.minWidth = '120'
                    break         
                
                default:
                    continue;
                    break;
            }
            tableHeadData.push(obj);
        }

       
        tableHeadData.sort((a, b) => a.tableOrder - b.tableOrder);
        return Object.freeze(tableHeadData)
    }

    tableHead_la(data) { //立案
        const tableHeadData = [];
        for (let i in data) {
            let obj = {};
            switch (i) {
                case 'enterpriseName':
                    obj.prop = i;
                    obj.label = '企业名称'
                    obj.tableOrder = 10
                    obj.minWidth = '250'
                    break 
                case 'caseNo':
                    obj.prop = i;
                    obj.label = '案号'
                    obj.tableOrder = 20
                    obj.minWidth = '250'
                    break
                case 'startDate':
                    obj.prop = i;
                    obj.label = '开始时间'
                    obj.tableOrder = 30
                    obj.minWidth = '120'
                    break    
                case 'endDate':
                    obj.prop = i;
                    obj.label = '结束时间'
                    obj.tableOrder = 40
                    obj.minWidth = '120'
                    break         
                case 'caseCause':
                    obj.prop = i;
                    obj.label =  '案由'
                    obj.tableOrder = 50
                    obj.minWidth = '150'
                    break         
                case 'court':
                    obj.prop = i;
                    obj.label =  '法院'
                    obj.tableOrder = 60
                    obj.minWidth = '130'
                    break         
                case 'region':
                    obj.prop = i;
                    obj.label =  '地区'
                    obj.tableOrder = 70
                    obj.minWidth = '70'
                    break         
                case 'caseStatus':
                    obj.prop = i;
                    obj.label =  '案件状态'
                    obj.tableOrder = 80
                    break         
                case 'hearingDate':
                    obj.prop = i;
                    obj.label =  '开庭日期'
                    obj.tableOrder = 90
                    obj.minWidth = '120'
                    break         
                
                default:
                    continue;
                    break;
            }
            tableHeadData.push(obj);
        }

       
        tableHeadData.sort((a, b) => a.tableOrder - b.tableOrder);
        return Object.freeze(tableHeadData)
    }

    tableHead_xzgxf(data) { //限高
        const tableHeadData = [];
        for (let i in data) {
            let obj = {};
            switch (i) {
                case 'enterpriseName':
                    obj.prop = i;
                    obj.label = '企业名称'
                    obj.tableOrder = 10
                    obj.minWidth = '250'
                    break 
                case 'executionApplicant':
                    obj.prop = i;
                    obj.label = '申请执行人'
                    obj.tableOrder = 20
                    obj.minWidth = '250'
                    break
                case 'caseNo':
                    obj.prop = i;
                    obj.label = '案号'
                    obj.tableOrder = 30
                    obj.minWidth = '250'
                    break    
                case 'filingDate':
                    obj.prop = i;
                    obj.label = '立案时间'
                    obj.tableOrder = 40
                    obj.minWidth = '120'
                    break         
                case 'releaseDate':
                    obj.prop = i;
                    obj.label =  '限制令发布日期'
                    obj.tableOrder = 50
                    obj.minWidth = '150'
                    break         
                case 'caseReason':
                    obj.prop = i;
                    obj.label =  '案由'
                    obj.tableOrder = 60
                    obj.minWidth = '250'
                    break         
                case 'court':
                    obj.prop = i;
                    obj.label =  '执行法院'
                    obj.tableOrder = 70
                    obj.minWidth = '130'
                    break         
                case 'name':
                    obj.prop = i;
                    obj.label =  '被限制消费人姓名'
                    obj.tableOrder = 80
                    break         
                       
                
                default:
                    continue;
                    break;
            }
            tableHeadData.push(obj);
        }

       
        tableHeadData.sort((a, b) => a.tableOrder - b.tableOrder);
        return Object.freeze(tableHeadData)
    }

    fomatData_EI(data){
        data.forEach(element => {
            element.createTime_view = element.createTime ? parseTime(new Date(element.createTime).getTime(), '{y}-{m}-{d} {h}:{i}:{s}') : null
            element.regTime_view = element.regTime ? parseTime(new Date(element.regTime).getTime(), '{y}-{m}-{d} {h}:{i}:{s}') : null
        });
        return data;
    }

    fomatData_ES(data){
        data.forEach(element => {
            element.createTime_view = element.createTime ? parseTime(new Date(element.createTime).getTime(), '{y}-{m}-{d} {h}:{i}:{s}') : null
            element.regTime_view = element.regTime ? parseTime(new Date(element.regTime).getTime(), '{y}-{m}-{d} {h}:{i}:{s}') : null
            element.dataTime_view = element.dataTime ? parseTime(new Date(element.dataTime).getTime(), '{y}-{m}-{d} {h}:{i}:{s}') : null
            element.gszcTime_view = element.gszcTime ? parseTime(new Date(element.gszcTime).getTime(), '{y}-{m}-{d} {h}:{i}:{s}') : null
        });
        return data;
    }


    async download(row){
        const { status,id } = row;
        if( status === '签署完成'){
            const res = await contractDownload({id});
            window.open(res.data,'_blank')
        }else{
            const res = await fileGet({fileId:id})
            //console.log('fileGet',res);
            window.open(res.data,'_blank')
        }
    }


    // deleteRow(row){
    //     const { id } = row;
    //     MessageBox.confirm(`确定删除?`, '提示', {
    //         confirmButtonText: '确定',
    //         cancelButtonText: '取消',
    //         type: 'warning'
    //     }).then(() => {
            
    //         fileDelete({ id }).then(res => {
    //             this.context.search()
    //         })
    //     }).catch(() => {
    //     });
    // }

    

    async getBanks(){
        return await getBanks();
    }

    //打开loading
    turnOnLoading(querySelector,text = '拼命读取中') {
        const target = Object.prototype.toString.call(querySelector) === '[object HTMLDivElement]' ? querySelector : document.querySelector(querySelector)
        //console.log('target',target)
        const loading = Loading.service({
            text,
            spinner: 'el-icon-loading',
            target
        });
        this.context.loading = this.context.loading ? [...this.context.loading,loading] : [loading]
        //console.log('this.context.loading ',this.context.loading )
        return this.context.loading
    }

    closeLoading(){
        if(Array.isArray(this.context.loading)){
            this.context.loading.length && this.context.loading.forEach(item => item.close());
            this.context.loading = [];
        }else{
            this.context.loading && this.context.loading.close();
        }
    }
}
